package com.yugao.fintech.draper.admin.controller;

import com.yugao.fintech.draper.admin.service.UserPostService;
import com.yugao.fintech.draper.datasource.entity.PageResult;
import com.yugao.fintech.draper.admin.param.UserPostDTO;
import com.yugao.fintech.draper.admin.param.UserPostQuery;
import com.yugao.fintech.draper.core.model.ResultVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userPost")
@RequiredArgsConstructor
@Tag(name = "用户岗位管理")
public class UserPostController {

	private final UserPostService userPostService;

	@Operation(summary = "查询用户岗位分页")
	@GetMapping(value = "/page")
	public ResultVO<PageResult<UserPostDTO>> pageQuery(UserPostQuery userPostQueryVo) {
		return ResultVO.success(PageResult.success(userPostService.pageQuery(userPostQueryVo)));
	}

	@Operation(summary = "添加用户岗位")
	@PostMapping(value = "/add")
	public ResultVO<Boolean> add(@RequestBody UserPostDTO userPostDto) {
		return ResultVO.success(userPostService.addUserPost(userPostDto));
	}

	@Operation(summary = "修改用户岗位")
	@PostMapping(value = "/update")
	public ResultVO<Boolean> update(@RequestBody UserPostDTO userPostDto) {
		return ResultVO.success(userPostService.updateUserPost(userPostDto));
	}

	@Operation(summary = "删除用户岗位")
	@DeleteMapping(value = "/delete")
	public ResultVO<Boolean> delete(Long id) {
		return ResultVO.success(userPostService.deleteUserPost(id));
	}

	@Operation(summary = "获取用户岗位详细信息")
	@GetMapping(value = "/findById")
	public ResultVO<UserPostDTO> findById(Long id) {
		return ResultVO.success(userPostService.findById(id));
	}

	@Operation(summary = "获取全部用户岗位")
	@GetMapping(value = "/findAll")
	public ResultVO<List<UserPostDTO>> findAll() {
		return ResultVO.success(userPostService.findAll());
	}

}